package ai.xiaodao.trade;

import ai.xiaodao.config.Security;
import com.futu.openapi.pb.TrdCommon;

public class TradeOps {
    /**
     * judge the current trade side
     *
     * @param curPrice
     * @return
     */
    public static int getTradeSide(double curPrice) {
        if (curPrice <= Security.getBuyTriggerPrice()) {
            return TrdCommon.TrdSide.TrdSide_Buy_VALUE;
        }
        if (curPrice >= Security.getSaleTriggerPrice()) {
            return TrdCommon.TrdSide.TrdSide_Sell_VALUE;
        }
        return 0;
    }

    /**
     * get the price by the trade side during place the order
     * @param tradeSide  trade side
     * @return the price of buy or sale
     */
    public static Double getTrdPrice(int tradeSide) {
        if (tradeSide == TrdCommon.TrdSide.TrdSide_Buy_VALUE)
            return Security.getBuyPrice();
        else
            return Security.getSalePrice();
    }

    /**
     * compare the local record with the call order weather equal
     * @param localOrder the order of local during placing order
     * @param order the order of futu callback
     * @return true if they are the same ,false if not
     */
    public static boolean  orderCmp(LocalOrder localOrder, TrdCommon.Order order) {
        return localOrder.getCode() == order.getCode() &&
                localOrder.getTrdSide() == order.getTrdSide() &&
                localOrder.getTrdQty() == order.getQty();
    }


}
